<?php
class Cl_Page extends WdkClass 
{
	protected
		/******************************************************/
		//	원본 테이블 정보
		/******************************************************/
		$page_seq		= 0		,	//	
		$page_id		= ''	,	//	
		$page_title		= ''	,	//	
		$page_content	= ''	,	//	
		$page_layout	= ''	,	//	
		$page_hits		= 0		,	//	
		$page_time		= 0		,	//	
		$page_del_flag	= 'F'	;	//	
		/******************************************************/
		//	추가 정보
		/******************************************************/
	
	/**
	 * 	
	 */
	function __construct()
	{
		parent::__construct();
		self::getDbo();
	}
	
	/**
	 *	
	 */
	public function __init($data)
	{
		parent::__init($data);
		self::dformat();
	}
	
	/**
	 *	
	 */
	public function load($page_seq)
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		self::__init($dbo->cLoad($page_seq));
	}
	
	/**
	 *	
	 */
	public function dformat()
	{
	
	}
	
	/**
	 * 
	 */
	public function autoUpdate($log='')
	{
		if((int)$this->page_seq > 0)
		{
			$this->update($log);
		}
		else
		{
			$this->insert($log);
		}
	}
	
	/**
	 *	
	 */
	public function insert($log='Insert')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		$this->page_hits	= 0;
		$this->page_time	= time();
		$this->page_del_flag		= 'F';
		
		$data = array(	'page_id'		=>	$this->page_id,
						'page_title'	=>	$this->page_title,
						'page_content'	=>	$this->page_content,
						'page_layout'	=>	$this->page_layout,
						'page_hits'		=>	$this->page_hits,
						'page_time'		=>	$this->page_time,
						'page_del_flag'	=>	$this->page_del_flag
					);
		$this->page_seq = $dbo->insert($data);
		/******************************************************/
		parent::setBackupData(array_keys($data));
		$this->backup($log);
		/******************************************************/
	}
	
	/**
	 * 
	 */
	public function update($log='update')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		if(parent::isUpdatable())
		{
			$data = array(	'page_title'		=>	$this->page_title,
							'page_content'		=>	$this->page_content,
							'page_layout'		=>	$this->page_layout
						);
			$dbo->update($data, array("page_seq = ".$this->page_seq));
			/******************************************************/
			parent::setBackupData(array_keys($data));
			$this->backup($log);
			/******************************************************/
		}
	}
	
	/**
	 * 
	 */
	public function delete($log='delete')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		$dbo->delete(array("page_seq = ".$this->page_seq));
		/******************************************************/
		parent::setBackupData();
		$this->backup($log);
		/******************************************************/
	}
	
	/**
	 * 
	 */
	public function hit()
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/

		$data = array(	'page_hits'			=>	$this->page_hits + 1
					);
		$dbo->update($data, array("page_seq = ".$this->page_seq));
	}
	
	/**
	 *	
	 */
	private function backup($log='')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		$dbo->log($this->page_seq, $log, $this->backup_data);
	}
	
	/**
	 * 
	 */
	public function getDbo()
	{
		return Wdk::model(substr(__CLASS__, 3));
	}
}